import WebVideoCreator, { VIDEO_ENCODER, logger } from "./index.js";

async function generateSimpleHDVideo() {
    const wvc = new WebVideoCreator();

    // 基础高清配置
    wvc.config({
        frameFormat: "png",          // 无损PNG
        frameQuality: 95,            // 高质量
        browserUseGPU: true,         // GPU加速
        ffmpegDebug: true,           // 开启FFmpeg调试
        debug: true                  // 开启调试
    });

    const video = wvc.createSingleVideo({
        content: `
        <!DOCTYPE html>
        <html>
        <head>
            <style>
                body { 
                    margin: 0; 
                    background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    height: 100vh;
                    font-family: Arial, sans-serif;
                }
                h1 {
                    font-size: 48px;
                    color: white;
                    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
                    animation: pulse 2s ease-in-out infinite;
                }
                @keyframes pulse {
                    0%, 100% { transform: scale(1); }
                    50% { transform: scale(1.1); }
                }
            </style>
        </head>
        <body>
            <h1>高清视频测试</h1>
        </body>
        </html>
        `,
        
        // 保守的高清设置
        width: 1280,             // 720p宽度
        height: 720,             // 720p高度
        fps: 30,                 // 30fps
        duration: 5000,          // 5秒
        
        // 质量设置
        videoQuality: 90,        // 90%质量
        pixelFormat: "yuv420p",  // 兼容性更好的格式
        
        outputPath: "./simple-hd-test.mp4",
        showProgress: true,
        consoleLog: true
    });

    logger.info("🚀 开始生成简单高清视频...");
    
    try {
        const result = await video.startAndWait();
        
        logger.success(`✅ 高清视频生成完成！
📹 分辨率: 1280x720 @ 30fps
📁 文件: ./simple-hd-test.mp4
⏱️  耗时: ${Math.floor(result.takes / 1000)}秒`);
        
        return result;
    } catch (error) {
        logger.error("❌ 生成失败:", error.message);
        throw error;
    }
}

// 运行测试
generateSimpleHDVideo().catch(console.error);